﻿@{
    ViewBag.Title = "PurchaseGeneral_View";
    Layout = "~/Views/Users/Index.cshtml";
}
<link href="~/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/js/jquery.min.js"></script>
<script src="~/js/bootstrap.min.js"></script>
<h2>商品一览</h2>
<form action="/Purchase/PurchaseGeneral_View" method="get">
    <table width="300">
        <tr>
            <td>
                <select name="Select1" class="form-control">
                    <option value="空">花卉名称</option>
                    <option value="郁金香">郁金香</option>
                    <option value="百合">百合</option>
                    <option value="茉莉">茉莉</option>
                    <option value="香草">香草</option>
                    <option value="牡丹">牡丹</option>
                </select>
            </td>
            <td>
                <input type="submit" value="查询" class="form-control" />
            </td>

        </tr>
    </table>
</form>


<table border="1" class="table-hover" width="500" style="text-align:center;">
    <tr>
        <th>商品编号</th>
        <th>商品名称</th>
        <th>单价</th>
        <th>数量</th>
        <th>操作</th>
    </tr>
    @{
        foreach (var item in Model)
        {
            <tr>
                <td>@item.commodityID</td>
                <td>@item.FlowersName</td>
                <td>@item.PurchasePrice</td>
                <td>
                    <input id="Num" type="text" style="width:70px;" />
                </td>
                <td>
                    <a href="#"  onclick="Procure(this)">采购</a>
                </td>
            </tr>
        }
    }
    
</table>
<script>
    function Procure(obj)
    {
        var proid= $(obj).parent().parent().children().eq(0).html();
        var flowername = $(obj).parent().parent().children().eq(1).html();
        var purprice = $(obj).parent().parent().children().eq(2).html();
        var num = $(obj).parent().parent().children().eq(3).children().val();
        

        $.ajax({
            type: "post",
            url: "/Purchase/PurchaseGeneralSession",
            data: { commodityID: proid, FlowersName: flowername, PurchasePrice: purprice, PurchaseNumber: num },
            success: function (result)
            {
                if (result!= 1)
                {
                    alert("采购成功！");
                    location.href = '/Purchase/Purchase_View';
                }
                else
                {
                    alert("采购失败！请选择数量！");
                    location.href = '/Purchase/PurchaseGeneral_View';
                }
            }
        })
        
    }
</script>





